package com.baizhi.controller;

import com.baizhi.entity.ProductSize;
import com.baizhi.entity.Result;
import com.baizhi.service.ProductSizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("productSize")
@Controller
public class ProductSizeController {

    @Autowired
    private ProductSizeService productSizeService;

    @RequestMapping("findAll")
    @ResponseBody
    public List<ProductSize> findAll(){
        return productSizeService.findAll();
    }

    @RequestMapping("findById")
    @ResponseBody
    public ProductSize findById(String id){
        return productSizeService.findById(id);
    }

    @RequestMapping("save")
    @ResponseBody
    public Result save(ProductSize productSize){
        Result result = null;
        try{
            productSizeService.save(productSize);

        }catch (Exception e){
            e.printStackTrace();
            result = new Result();
            result.setMessage("添加失败");
        }
        return  result;
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(ProductSize productSize){
        Result result = null;
        try{
            productSizeService.update(productSize);
            result = new Result();
            result.setStatus(true);
            result.setMessage("更新失败");
        }catch (Exception e){
            e.printStackTrace();
            result = new Result();
            result.setMessage("更新失败");
        }
        return result;
    }

    @RequestMapping("delete")
    public Result delete(String id){
        Result result = null;
        try{
            productSizeService.delete(id);
            result = new Result();
            result.setStatus(true);
        }catch (Exception e){
            e.printStackTrace();
            result = new Result();
            result.setMessage("失败");
        }
        return result;
    }
}
